from typing import Dict, List, Any


class Cell:
    '''单元格'''

    def __init__(self) -> None:
        self.id = 0         # 单元格id
        self.word = ''      # 内容
        self.xsc = 0        # 横轴上起始于0格
        self.xec = 0        # 横轴上终止于0格
        self.ysc = 0        # 纵轴上起始于0格
        self.yec = 0        # 纵轴上终止于0格
    
    @staticmethod
    def from_json(json: Dict[str, Any]) -> 'Cell':
        result = Cell()
        result.id = json.get('tableCellId', 0)
        result.word = json.get('word', '')
        result.xsc = json.get('xsc', 0)
        result.xec = json.get('xec', 0)
        result.ysc = json.get('ysc', 0)
        result.yec = json.get('yec', 0)
        return result


class Table:
    '''表格'''

    def __init__(self) -> None:
        self.id = 0         # 表格id
        self.xCellSize = 1  # 几行
        self.yCellSize = 1  # 几列3
        self.cells: List[Cell] = []     # 表格内的单元格

    @staticmethod
    def from_json(json: Dict[str, Any]) -> 'Table':
        result = Table()
        result.id = json.get('tableId', 0)
        result.xCellSize = json.get('xCellSize', 0)
        result.yCellSize = json.get('yCellSize', 0)
        for cell_info in json.get('cellInfos', []):
            result.cells.append(Cell.from_json(cell_info))
        return result
